package com.sheng.leetcode.year2023.month03.day31;

import org.junit.Test;

/**
 * @author liusheng
 * @date 2023/03/31
 * <p>
 * 2367. 算术三元组的数目<p>
 * <p>
 * 给你一个下标从 0 开始、严格递增 的整数数组 nums 和一个正整数 diff 。<p>
 * 如果满足下述全部条件，则三元组 (i, j, k) 就是一个 算术三元组 ：<p>
 * i < j < k ，<p>
 * nums[j] - nums[i] == diff 且<p>
 * nums[k] - nums[j] == diff<p>
 * 返回不同 算术三元组 的数目。<p>
 * <p>
 * 示例 1：<p>
 * 输入：nums = [0,1,4,6,7,10], diff = 3<p>
 * 输出：2<p>
 * 解释：<p>
 * (1, 2, 4) 是算术三元组：7 - 4 == 3 且 4 - 1 == 3 。<p>
 * (2, 4, 5) 是算术三元组：10 - 7 == 3 且 7 - 4 == 3 。<p>
 * <p>
 * 示例 2：<p>
 * 输入：nums = [4,5,6,7,8,9], diff = 2<p>
 * 输出：2<p>
 * 解释：<p>
 * (0, 2, 4) 是算术三元组：8 - 6 == 2 且 6 - 4 == 2 。<p>
 * (1, 3, 5) 是算术三元组：9 - 7 == 2 且 7 - 5 == 2 。<p>
 * <p>
 * 提示：<p>
 * 3 <= nums.length <= 200<p>
 * 0 <= nums[i] <= 200<p>
 * 1 <= diff <= 50<p>
 * nums 严格 递增<p>
 * <p>
 * 来源：力扣（LeetCode）<p>
 * 链接：<a href="https://leetcode.cn/problems/number-of-arithmetic-triplets">2367. 算术三元组的数目</a><p>
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。<p>
 */
public class LeetCode2367 {

    @Test
    public void test01() {
//        int[] nums = {0, 1, 4, 6, 7, 10};
//        int diff = 3;
        int[] nums = {4, 5, 6, 7, 8, 9};
        int diff = 2;
        System.out.println(new Solution().arithmeticTriplets(nums, diff));
    }
}

class Solution {
    public int arithmeticTriplets(int[] nums, int diff) {
        int ans = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[k] - nums[j] == diff && nums[j] - nums[i] == diff) {
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
}
